package bean.back.login;

import com.alibaba.fastjson.JSON;
import util.JDBCConnection;

import java.sql.ResultSet;
import java.util.Date;

public class BackloginBean {
    int code;
    String message;
    String token;

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public String getToken() {
        return token;
    }

    public void setToken(String token) {
        this.token = token;
    }

    public String login(String operator_id,String operator_pwd){
        JDBCConnection jdbc = new JDBCConnection();
        String querySQL = "select backpsd from backstage where backaccount = '"+operator_id+"'";
        ResultSet rs = jdbc.executeQuery(querySQL);
        try {
            if(rs.next()){
                if(operator_pwd.equals(rs.getString("backpsd"))){
                    code = 0;
                    message = "成功";
                    Date date = new Date();
                    token = operator_id+"#"+date.getTime()+"#"+operator_pwd;
                }else{
                    code = 1000;
                    message = "登录密码错误";
                }
            }else {
                message = "登录账户不存在";
                code =1001;
            }
        }catch (Exception e){
            code = 100;
            message = e.toString();
        }
        return JSON.toJSONString(this);
    }
}
